import React from 'react';
import { withRouter } from 'react-router-dom';
import { observer, inject } from 'mobx-react';
import { searchToQuery } from '../../util';
import View from './View';

/**
 * 支持从地址栏传入参数的View,只在第一层路由使用
 */
@inject('viewStore')
@withRouter
@observer
export default class WriteByLocation extends React.Component {
  //解决单页路由时，params制空问题
  // componentDidMount() {
  //   this.setParamByLocation(this.props.location.search)
  // }
  
  // componentWillReceiveProps(nextProps) {
  //   if (nextProps.location.search !== this.props.location.search) {
  //     this.setParamByLocation(nextProps.location.search);
  //   }
  // }
  
  setParamByLocation = (search) => {
    const { viewStore } = this.props;
    viewStore.setState({ params: searchToQuery(search) });
  }
  
  render() {
    return (
      <View path="/view"/>
    );
  }
}